package com.program.cloudmanage.tripteam.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.program.cloudmanage.tripteam.domain.Itinerary;
import com.program.cloudmanage.tripteam.service.ItineraryService;
import com.program.cloudmanage.tripteam.service.TripTeamService;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.PutObjectResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/Itinerary")
public class ItineraryController {
    @NacosInjected
    @Autowired
    private ItineraryService itineraryService;
    @Autowired
    private TripTeamService tripTeamService;

    @GetMapping("/Itinerary")
    public List<Itinerary> showItineraries(){
        return itineraryService.showItineraries();
    }

    @GetMapping("/test")
    public String test(){
        return "hello world";
    }

    @PostMapping("/searchItinerary")
    public Itinerary searchItinerary(@RequestBody Itinerary itinerary){
        return itineraryService.searchItinerary(itinerary.getItineraryid());
    }
    @PostMapping("/searchItineraryByTeamId")
    public List<Itinerary> searchItineraryByTeamId(@RequestBody Itinerary itinerary){
        return itineraryService.searchItineraryByTeamId(itinerary.getTeamid());
    }

    @PostMapping("/insertItinerary")
    public String insertItinerary(@RequestBody Itinerary itinerary){
        itineraryService.insertItinerary(itinerary);
        return "OK";
    }

    @PostMapping ("/deleteItinerary")
    public String deleteItinerary(@RequestBody Itinerary itinerary){
        itineraryService.deleteItinerary(itinerary.getItineraryid());
        return "OK";
    }


    @PostMapping("/updateItinerary")
    public String updateItinerary(@RequestBody Itinerary itinerary) {
        itineraryService.updateItinerary(itinerary);
        String id = itinerary.getItineraryid();
        String pass = itinerary.getPass();
        String id2 = String.valueOf(Integer.valueOf(id)*100);
        COSClient cosClient = tripTeamService.createCOSClient();
        PutObjectResult putObjectResult = cosClient.putObject("red3and-1325710075",id2,pass );
        return "OK";
    }


}
